package com.ydl.shopping.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ydl.shopping.core.entity.BaseEntity;
import com.ydl.shopping.core.valid.ValidGroup;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.NotBlank;
import java.util.ArrayList;
import java.util.List;

/** 菜单表 */
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("tb_menu")
@Schema(name = "菜单表")
public class TbMenu extends BaseEntity {
    /** 菜单名称 */
    @TableField("name")
    @NotBlank(groups = ValidGroup.Crud.Create.class, message = "菜单名称不能为空")
    @NotBlank(groups = ValidGroup.Crud.Update.class, message = "菜单名称不能为空")
    @Schema(description = "菜单名称")
    private String name;

    /** 菜单图标 */
    @TableField("icon")
    @Schema(description = "菜单图标")
    private String icon;

    /** 图标样式 */
    @TableField("icon_style")
    @Schema(description = "图标样式")
    private String iconStyle;

    /** 路由路径 */
    @TableField("path")
    @Schema(description = "路由路径")
    private String path;

    /** 路由组件 */
    @TableField("component")
    @Schema(description = "路由组件")
    private String component;

    /** 路由参数 */
    @TableField("meta")
    @Schema(description = "路由参数")
    private String meta;

    /** 上级ID，无则为0 */
    @TableField("parent_id")
    @Schema(description = "上级ID")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long parentId;

    /** 菜单层次，0为一级菜单 */
    @TableField("level")
    @Schema(description = "菜单层次")
    private Integer level;

    /** 排序 */
    @TableField("sort")
    @Schema(description = "排序")
    private Integer sort;

    /** 是否可见，0：隐藏，1：显示 */
    @TableField("is_visible")
    @Range(min = 0, max = 1, message = "是否可见，0：隐藏，1：显示")
    @Schema(description = "是否可见")
    private Integer isVisible;

    /** 节点类型 0：文件，1：菜单，2：按钮 */
    @TableField("node_type")
    @Range(min = 0, max = 2, message = "节点类型 0：文件，1：菜单，2：按钮")
    @Schema(description = "节点类型")
    private Integer nodeType;

    /** 权限标识 */
    @TableField("perms")
    @Schema(description = "权限标识")
    private String perms;

    /** 权限状态 */
    @TableField("status")
    @Range(min = 0, max = 1, message = "权限状态，0：禁用，1：可用")
    @Schema(description = "权限状态")
    private Integer status;

    /** 是否删除，0：否，1：是 */
    @TableLogic
    @TableField("is_del")
    @Schema(description = "是否删除", hidden = true)
    private Integer isDel;

    /** 子菜单列表 */
    @TableField(exist = false)
    @Schema(description = "子菜单列表")
    private List<TbMenu> children = new ArrayList<>();
}
